/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.MediumManagement;

import Utilities.Functions;
import Utilities.PermissionsConstants;

/**
 * Instances of this class are used by the user interface when a request to
 * open a floppy disk is sent to the media management service.
 *
 * @author Angel Sanadinov
 */
public class OpenFloppyDiskRequest extends MediumManagementRequest
{
    private String location;    //the location of the floppy disk on the host
    private String imageId;     //the image id, which the floppy disk will get
    private String permissions; //the permissions of the DVD

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     */
    public OpenFloppyDiskRequest()
    {
        setRequestedAction(PermissionsConstants.ACTION_MEDIUM_OPEN_FDD);
        this.location = null;
        this.imageId = null;
    }

    /**
     * Constructs an "open floppy disk" request with the specified data. <br><br>
     *
     * <b>Note:</b> <i>The floppy disk image UUID is automatically set by VirtualBox.</i>
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the disk resides
     * @param location the location of the floppy disk on the host system
     * @param permissions permissions data for the floppy disk
     */
    public OpenFloppyDiskRequest(int requestorId, int serverId, String location, String permissions)
    {
        setRequestedAction(PermissionsConstants.ACTION_MEDIUM_OPEN_FDD);
        this.permissions = permissions;
        setRequestorId(requestorId);
        setServerId(serverId);
        this.location = location;
    }

    /**
     * Constructs an "open floppy disk" request with the specified data. <br><br>
     *
     * <b>Note:</b> <i>The floppy disk image UUID is explicitly set from
     * the UUID in <code>imageId</code>.</i>
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the disk resides
     * @param location the location of the floppy disk on the host system
     * @param imageId the id of the new floppy disk
     * @param permissions permissions data for the floppy disk
     */
    public OpenFloppyDiskRequest(int requestorId, int serverId, String location, String imageId, String permissions)
    {
        this(requestorId, serverId, location, permissions);
        this.imageId = imageId;
    }

    /**
     * Retrieves the location of the floppy disk on the host system.
     *
     * @return the floppy disk location
     */
    public String getLocation()
    {
        return location;
    }

    /**
     * Retrieves the explicit floppy disk image id.
     *
     * @return the image id, if available or <code>null</code> otherwise
     */
    public String getImageId()
    {
        return imageId;
    }

    /**
     * Retrieves the permissions of the new floppy disk.
     *
     * @return the Floppy disk's permissions
     */
    public String getPermissions()
    {
        return permissions;
    }

    /**
     * Sets the location of the floppy disk image.
     *
     * @param location the floppy disk image location
     */
    public void setLocation(String location)
    {
        this.location = location;
    }

    /**
     * Sets the explicit floppy disk image id.
     *
     * @param imageId the image id
     */
    public void setImageId(String imageId)
    {
        this.imageId = imageId;
    }

    /**
     * Sets the permissions of the new floppy disk.
     *
     * @param permissions the floppy disk's permissions
     */
    public void setPermissions(String permissions)
    {
        this.permissions = permissions;
    }

    @Override
    public boolean isValid()
    {
        if(super.isValid() && Functions.isLocationValid(location) 
                && Functions.arePermissionsValid(permissions)
                && (imageId == null || Functions.isUUIDValid(imageId)))
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (mediumId,location,imageId,permissions)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return OpenFloppyDiskRequest.class.getSimpleName() + ": (" + getMediumId()
                + "," + location + "," + imageId + "," + permissions + ")";
    }
}
